//order=['projet','epic','scenario','userstory'];
var bdd_json;
function json2graph(bad){//TODO:recursiv
	function getChildrensById(elem,id){
		var ret=[];
		for(var e in elem){
			if(elem[e].fk_project_id==id || elem[e].fk_epic_id==id || elem[e].fk_userstory_id==id)
				ret.push(elem[e]);
		}
		return ret;
	}
	IHM.updateMenu(bad);
	if(bad.project.length==0)return null;
	bdd_json=bad;
	var p={};
	p.id="project_"+1;
	p.data=bad.project[0];
	p.name=bad.project[0].name;
	p.children=[];
	var epics=getChildrensById(bad.epic,bad['project'][0].id);//recup les epic du projet
	for(var epic in epics){//a chaque epic
		var e = {data:bad['epic'][epic]};
		e.id="epic_"+e.data.id;
		e.name=e.data.name;
		e.children=[];
		var userstorys=getChildrensById(bad['userstory'],e.data.id);//recup les US de l'epic du projet en cours
		for(var us in userstorys){
			var u = {data:userstorys[us]};
			u.id="userstory_"+u.data.id;
			u.name=u.data.name;
			u.children=[];
			var scenars=getChildrensById(bad['scenario'],u.data.id);//recup les scenar de l'US de l'epic du projet en cours
			for(var sc in scenars){
				var s = {data:scenars[sc]};
				s.id="scenario_"+s.data.id;
				s.name=s.data.name;
				s.children=[];
				//we need to go deeper
				u.children.push(s);
			}
			e.children.push(u);
		}
		p.children.push(e);//ajouter l'epic a la l'arbre
	}
	return p;
}